//
//  icloudTests.swift
//  icloudTests
//
//  Created by raymond on 2022/5/20.
//

import XCTest
@testable import icloud
import Foundation

class icloudTests: XCTestCase {
  
  override func setUpWithError() throws {
    // Put setup code here. This method is called before the invocation of each test method in the class.
  }
  
  override func tearDownWithError() throws {
    // Put teardown code here. This method is called after the invocation of each test method in the class.
  }
  
  func testExample() throws {
    // This is an example of a functional test case.
    // Use XCTAssert and related functions to verify your tests produce the correct results.
    // Any test you write for XCTest can be annotated as throws and async.
    // Mark your test throws to produce an unexpected failure when your test encounters an uncaught error.
    // Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards.
    test01()
  }
  
  func testPerformanceExample() throws {
    // This is an example of a performance test case.
    self.measure {
      // Put the code you want to measure the time of here.
    }
  }
  
  func test01(){
    struct Response<T: Codable>: Codable {
      var success: Bool
      var message: String
      var data: [T]
    }
    struct User: Codable {
      var name: String
    }
    
    let json = """
    {
        "success": true,
        "message": "hello json",
        "data": [{
          "name": "diablo"
        }]
    }
    """.data(using: .utf8)!
    
    do {
      let decoder = JSONDecoder()
      let resp = try decoder.decode(Response<User>.self, from: json)
      print("resp:"+String(resp.data[0].name))
    } catch {
      print("error:\n\(error)")
    }
  }
}
